<template>
  <el-card style="margin-bottom: 10px">
    <el-form
      :disabled="cc.isShow"
      :inline="true"
      lass="demo-form-inline my-category"
    >
      <el-form-item label="一级分类">
        <el-select v-model="category1Id" placeholder="请选择">
          <el-option
            v-for="c1 in categoryStore.category1List"
            :key="c1.id"
            :label="c1.name"
            :value="c1.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select v-model="category2Id" placeholder="请选择">
          <el-option
            v-for="c2 in categoryStore.category2List"
            :key="c2.id"
            :label="c2.name"
            :value="c2.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="category3Id" placeholder="请选择">
          <el-option
            v-for="c3 in categoryStore.category3List"
            :key="c3.id"
            :label="c3.name"
            :value="c3.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

// <script lang="ts">
// export default {
//   name: "CategorySelector",
//   // props:['isForbiddenForm'],
//   props: {
//     isShow: {
//       type: Boolean,
//     },
//   },
// };
//
</script>

<script lang="ts" setup>
import { computed, onMounted, ref } from "vue";
// 引入pinia中状态
import { useCategoryListStore } from "@/stores/categoryList";
// // 接受传过来的参数
const cc = defineProps(["isShow"]);

// console.log(cc);



// 导出的pinia实列对象
const categoryStore = useCategoryListStore();

// 计算属性来检测一级导航信息是否更改
const category1Id = computed({
  get() {
    return categoryStore.category1Id as number;
  },
  set(val: number) {
    // 当信息发生改变就发送请求获取二级导航数据
    categoryStore.getCategory2ListData(val);
  },
});

// 计算属性来检测一级导航信息是否更改
const category2Id = computed({
  get() {
    return categoryStore.category2Id as number;
  },
  set(val: number) {
    // 当信息发生改变就发送请求获取二级导航数据
    categoryStore.getCategory3ListData(val);
  },
});

// 计算属性来检测一级导航信息是否更改
const category3Id = computed({
  get() {
    return categoryStore.category3Id as number;
  },
  set(val: number) {
    // 当信息发生改变就发送请求获取二级导航数据
    // categoryStore.getCategory3ListData(val);
    categoryStore.saveCategory3Id(val);
  },
});

onMounted(async () => {
  categoryStore.getCategory1ListData();
});
</script>

<style scoped lang="scss">
.my-category {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>